<?php
namespace app\api\controller;
use think\Controller;
class Admin extends Base
{
    public function index()
    {   
        return $this->fetch();
    }  
   //系统首页数据
    public function getNums()
    {   
       //待支付
        $data1 = [
              'zhuangtai'=>1,
              'status'=>-1,
         ];
         //待发货
         $data2 = [
             'zhuangtai'=>1,
             'status'=>1,
         ];
         //已发货
         $data3 = [
            'zhuangtai'=>1,
            'status'=>0,
         ];
         //已完成
         $data4 = [
             'zhuangtai'=>1,
             'status'=>2,
         ];
        $membersNum = model('user')->where('zhuangtai',1)->select();
        $caigousNum = model('caigou')->where('zhuangtai',1)->select();
        $dzfNum = model('ordermaster')->where($data1)->select();
        $dfhNum = model('ordermaster')->where($data2)->select();
        $yfhNum = model('ordermaster')->where($data3)->select();
        $ywcNum = model('ordermaster')->where($data4)->select();
        if ($membersNum&&$caigousNum&&$dzfNum&&$dfhNum&&$yfhNum&&$ywcNum) {
              $json['success'] = 'true';
              $json['msg'] = '系统首页数据获取成功';
              $json['status'] = 200;
              $json['membersNum'] = count($membersNum);
              $json['caigousNum'] = count($caigousNum);
              $json['dzfNum'] = count($dzfNum);
              $json['dfhNum'] = count($dfhNum);
              $json['yfhNum'] = count($yfhNum);
              $json['ywcNum'] = count($ywcNum);
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
         }else{
                $json['success'] = 'false';
                $json['msg'] = '系统首页数据获取成功';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;
            }
    }

   public function getVegetables()
   {   
       $vegetables = model('vegetables')->VegetablesList();
        if ($vegetables) {
              $json['success'] = 'true';
              $json['msg'] = '蔬菜商品数据获取成功';
              $json['status'] = 200;
              $json['data'] = $vegetables;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
         }else{
                $json['success'] = 'false';
                $json['msg'] = '蔬菜商品数据获取失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;
            }
   }
 
  //添加商品
   public function addVegetables($vname,$price,$xlleixing,$pzleixing,$shangjia)
   {
         $data = [
               'url'=>20,
                'price'=>$price,
               'xlleixing'=>$xlleixing,
               'pzleixing'=>$pzleixing,
               'gid'=>$shangjia,
               'vname'=>$vname,
               'zhuangtai'=>1,
          ];
          $count = model('vegetables')->insert($data);
       if ($count) {
              $json['success'] = 'true';
              $json['msg'] = '添加蔬菜商品成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
         }else{
                $json['success'] = 'false';
                $json['msg'] = '添加蔬菜商品失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;
            }
   }

 //修改蔬菜商品信息
 public function editVegetables($vid,$vname,$price,$xlleixing,$pzleixing,$shangjia)
 {
          $data = [
               'url'=>20,
                'price'=>$price,
               'xlleixing'=>$xlleixing,
               'pzleixing'=>$pzleixing,
               'gid'=>$shangjia,
               'vname'=>$vname,
               'zhuangtai'=>1,
          ];
          $count = model('vegetables')->where('vid',$vid)->update($data);
       if ($count) {
              $json['success'] = 'true';
              $json['msg'] = '添加蔬菜商品成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
         }else{
                $json['success'] = 'false';
                $json['msg'] = '添加蔬菜商品失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;
            }
 }
 //获取一条蔬菜信息
   public function getVegetableById($vid){
     $data = [
        'v.zhuangtai' =>1,
        'v.vid'=>$vid
      ];
          $vegetables = model('Vegetables')
                      ->alias("v")
                      ->join('gongyingshang g','g.gid=v.gid','LEFT')
                      ->field('v.vid,v.url,v.pzleixing,v.xlleixing,v.vname,v.price,g.gname')
                      ->where($data)
                      ->select();

       if ($vegetables) {
             $json['success'] = 'true';
              $json['msg'] = '该蔬菜商品获取成功';
              $json['status'] = 200;
              $json['data'] = $vegetables;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
        }else{
                $json['success'] = 'false';
                $json['msg'] = '该蔬菜商品获取失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
   }

   //删除蔬菜
   public function delVegetables($vid)
   {     

        $count = model('vegetables')->where('vid',$vid)->setField('zhuangtai',-1);
         if ($count) {
             $json['success'] = 'true';
              $json['msg'] = '该蔬菜商品删除成功';
             $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
        }else{
                $json['success'] = 'false';
                $json['msg'] = '该蔬菜商品删除失败';
                $json['status'] =500;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
   }
   //获取供应商信息
   public function getGongyingshang()
   {
      $gongyingshang = model('gongyingshang')->getGongyingshang();
      if ($gongyingshang) {
             $json['success'] = 'true';
              $json['msg'] = '供应商数据获取成功';
              $json['status'] = 200;
              $json['data'] = $gongyingshang;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '供应商数据获取失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
   }

   //得到gid的一条供应商信息
   public function getEditGongyingshang($gid)
   {
      $gongyingshang = model('gongyingshang')
                          ->field('gname,phone,email,dizhi') 
                          ->where('gid',$gid)
                          ->find();
      if ($gongyingshang) {
             $json['success'] = 'true';
              $json['msg'] = '成功获取需要修改的供应商信息';
              $json['status'] = 200;
              $json['data'] = $gongyingshang;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '获取需要修改的供应商信息失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
   }
   
   public function editGongyingshang($gid,$gname,$phone,$email,$dizhi)
   {
     return $count = model('gongyingshang')->editGongyingshang($gid,$gname,$phone,$email,$dizhi);
   }
 
   //添加供应商
   public function addGongyingshang($gname,$phone,$email,$dizhi)
   {
       $count = model('gongyingshang')->inserGongyingshang($gname,$phone,$email,$dizhi);
      if ($count) {
             $json['success'] = 'true';
              $json['msg'] = '添加供应商成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '添加供应商失败';
                $json['status'] =500;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
   }
   
   //获取所有会员信息
    public function getMembers()
    {
       $members = model('user')
                      ->field('uid,username,zhanghao,mobile,password,vip,jifen,zhuangtai,token,userleixing')
                      ->where('status',1)
                      ->select();
      if ($members) {
             $json['success'] = 'true';
              $json['msg'] = '获取用户数据成功';
              $json['status'] = 200;
              $json['data'] = $members;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '获取用户数据失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }

    }
    public function memberEnable($uid)
    {
       $res = model('user')->where('uid',$uid)->setField('zhuangtai',1);
      if ($res) {
             $json['success'] = 'true';
              $json['msg'] = '用户启用成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '用户启用失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
    }

    public function memberDisable($uid)
    {
       $res = model('user')->where('uid',$uid)->setField('zhuangtai',-1);
      if ($res) {
             $json['success'] = 'true';
              $json['msg'] = '用户禁用成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '用户禁用失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
    }

    public function memberDel($uid)
    {
       $res = model('user')->where('uid',$uid)->setField('status',-1);
     if ($res) {
             $json['success'] = 'true';
              $json['msg'] = '用户删除成功';
              $json['status'] = 200;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
      }else{
                $json['success'] = 'false';
                $json['msg'] = '用户删除失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
      }
    }

    public function getJifen($token)
    {  
      //echo $token;
      $res = model('jifen')
                  ->field('id,bianhao,leixing,number')
                  ->where('token',$token)
                  ->select();
              //    dump($res);exit();
         $time = model('jifen')->where('token',$token)->column('create_time');
        //echo count($res);  
         for ($i=0; $i < count($res); $i++) { 
                  $res[$i]['time']=$time[$i];           
          }     
           
        if ($res) {
             $json['success'] = 'true';
              $json['msg'] = '用户积分获取成功';
              $json['status'] = 200;
              $json['data']=$res;
              $m = json_encode($json,JSON_UNESCAPED_UNICODE);
              echo $m;
        }else{
                 $json['success'] = 'false';
                $json['msg'] = '用户积分获取失败';
                $json['status'] =400;
                $m = json_encode($json,JSON_UNESCAPED_UNICODE);
                echo $m;  
       }
    }


      //添加用户
      public function regist($username,$zhanghao,$password,$mobile)
      {    
           $count = model('user')->insert($username,$zhanghao,$password,$mobile);
           if ($count) {
               $json['success']='true';
               $json['msg']='注册成功';
               $json['status']='200';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m;          
           }else{
               $json['success']='false';
               $json['msg']='注册失败';
               $json['status']='500';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m;     
           }
      }

      //查找zhanghao为$zhanghao的用户的uid,将该uid插入到xhmimagui
      public function getxhgui($zhanghao)
      {
          $res = model('user')->where('zhanghao',$zhanghao)->find();
           $id = model('xhmimagui')->insert($res->uid);
           if ($id) {
               $json['success']='true';
               $json['msg']='鲜活密码柜创建成功';
               $json['zhanghao']=$zhanghao;
               $json['bianhao']=$id;
               $json['status']='200';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m;    
           }else{
               $json['success']='false';
               $json['msg']='鲜活密码柜创建失败';
               $json['status']='500';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m; 
           }
      }


     public function getybgui($zhanghao)
     {
          $res = model('user')->where('zhanghao',$zhanghao)->find();
           $id = model('ybmimagui')->insert($res->uid);
           if ($id) {
               $json['success']='true';
               $json['msg']='一般蔬菜商品密码柜创建成功';
               $json['zhanghao']=$zhanghao;
               $json['bianhao']=$id;
               $json['status']='200';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m;    
           }else{
               $json['success']='false';
               $json['msg']='一般蔬菜商品创建失败';
               $json['status']='500';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m; 
           }       
     }      

     //保存$phone到verifycode表中
     public function savePhone($mobile)
     {
        $id = model('verifycode')->insertPhone($mobile);
         if ($id) {
               $json['success']='true';
               $json['msg']='成功添加手机验证码登录功能';
               $json['status']='200';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m;    
           }else{
               $json['success']='false';
               $json['msg']='添加手机验证码登录功能失败';
               $json['status']='500';
             $m = json_encode($json,JSON_UNESCAPED_UNICODE);
             echo $m; 
           }       
     }

           //根据手机号码去用户表查询该手机号码是否已经被注册
      public function verifyPhone($mobile)
      {
         $res = model('user')->where('mobile',$mobile)->find();
         if ($res) {
            $json['success']='false';
            $json['msg']='该号码已被注册';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='true';
            $json['msg']='该号码可以注册';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }
      }
      //根据账号去用户表查询该账号是否已经被注册
      public function verifyZhangHao($zhanghao)
      {
         $res = model('user')->where('zhanghao',$zhanghao)->find();
         if ($res) {
            $json['success']='false';
            $json['msg']='该账号已被注册';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='true';
            $json['msg']='该账号可以注册';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }
      }

      public function getOrdermaster()
      {
         $res = model('ordermaster')->field('id,bianhao,token,status,pay,servicetime,totalPrice,post')->select();
         $time = model('ordermaster')->column('create_time');
       //  dump($time);exit();
           for ($i=0; $i < count($res); $i++) { 
             $res[$i]['time']=$time[$i];           
          }; 
         if ($res) {
            $json['success']='true';
            $json['msg']='成功获取订单信息';
            $json['status']=500;
            $json['data']=$res;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='获取订单信息失败';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
      }

      public function getOrderDetail($bianhao)
      {
          $res = model('vegetables')
                 ->alias('v')
                 ->join('orderdetail o','v.vid=o.vid')
                 ->join('gongyingshang g','v.gid=g.gid')
                 ->field('g.gname,v.vname,o.num,g.phone,g.email,g.dizhi')
                 ->where(['o.bianhao'=>$bianhao])
                 ->select();
            for ($i=0; $i <count($res) ; $i++) { 
               $res[$i]['xuhao'] = $i+1;
            };
                // dump($res);exit();
            if ($res) {
            $json['success']='true';
            $json['msg']='订单详情数据获取成功';
            $json['status']=500;
            $json['data']=$res;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='订单详情数据获取失败';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
      }

      // 上传图片
      public function add_url()
    {
          $upload = new \Think\Upload();// 实例化上传类
          $upload->maxSize   =     3145728 ;// 设置附件上传大小
          $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
          $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
          $upload->savePath  =     ''; // 设置附件上传（子）目录
          // 上传文件 
          $info   =   $upload->upload();
          $path=ltrim($path,'.');
          $path = SITE_URL."/Uploads/".$path.$info["url"]["savepath"].$path.$info["url"]["savename"];
              
          $addc = D("vegetables");       
          $addc->create();//自动收集表单,创建出数据
          $data['url']=$path;
          $result=$addc->add($data);//把收集的表单添加到数据库
        
      }
     
     public function getOrder($token)
     {
         $res = model('user')
                 ->field('username,mobile')
                 ->where('token',$token)
                 ->find();
        if ($res) {
            $json['success']='true';
            $json['msg']='收货人信息获取成功';
            $json['status']=500;
            $json['username']=$res->username;
            $json['mobile']=$res->mobile;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='收货人信息获取失败';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }    
     }
     
     //发布采购信息
     public function postInfo($bianhao,$token,$jifen)
     {
         $res = model('caigou')->postInfo($bianhao,$token,$jifen);
        if ($res) {
            $json['success']='true';
            $json['msg']='发布信息成功插入数据库';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='发布信息插入数据库失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }   
     }
     //发布信息，改变发布按钮状态为禁用状态
    public function btnStatus($bianhao)
    {   
        $res = model('ordermaster')->where('bianhao',$bianhao)->setField('post',-1);
        if ($res) {
            $json['success']='true';
            $json['msg']='发布按钮已被禁用';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='发布按钮禁用失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }  

    }

    //获取采购列表信息
    public function getCaigou()
    {
        $res = model('caigou')
                   ->field('id,token,bianhao,jifen,status')
                   ->where('zhuangtai',1)
                   ->select();
          $time = model('caigou')->where('zhuangtai',1)->column('create_time');  
         for ($i=0; $i < count($res); $i++) { 
                  $res[$i]['time']=$time[$i];           
          };  

        if ($res) {
            $json['success']='true';
            $json['msg']='采购数据获取成功';
            $json['status']=200;
            $json['data']=$res;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='采购信息获取失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }     
    }

   //采购订单审核通过
    public function orderEnable($id,$bianhao)
    {
       $res = model('caigou')->where('id',$id)->setField('status',1);
       $res = model('ordermaster')->where('bianhao',$bianhao)->setField('status',0);
        if ($res) {
            $json['success']='true';
            $json['msg']='审核通过';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='审核通过失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }  
    }

      //采购订单审核不通过
    public function orderDisable($id,$bianhao)
    {
       $res = model('caigou')->where('id',$id)->setField('status',2);
       $res2 = model('caigou')->where('id',$id)->setField('caigouyuan','');
       $res3 = model('ordermaster')->where('bianhao',$bianhao)->setField('post',1);
        if ($res) {
            $json['success']='true';
            $json['msg']='审核不通过';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='审核不通过失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }  
    }

    //删除采购订单
    public function orderDel($id)
    {
      $res = model('caigou')->where('id',$id)->setField('zhuangtai',-1);
        if ($res) {
            $json['success']='true';
            $json['msg']='采购订单删除成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='采购订单删除失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }

    //获取token用户信息
    public function getUserInfo($token)
    {
        $res = model('user')->field('uid,username,userleixing')->where('token',$token)->find();
       if ($res) {
            $json['success']='true';
            $json['msg']='获取该用户信息成功';
            $json['status']=200;
            $json['data'] = $res;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='获取该用户信息失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }
    //计算用户所获总积分
    public function  getJifenJL($token)
    {   
        $data = [
            'token'=>$token,
            'leixing'=>1
        ];
         $res1 = model('jifen')->where($data)->select();
         $count1 = count($res1);
         $res2 = model('user')->where('token',$token)->find();
         $count2 = $res2->vip;
       if (true) {
            $json['success']='true';
            $json['msg']='获取用户购买商品获得积分次数成功';
            $json['status']=200;
            $json['count1'] = $count1;
            $json['count2'] = $count2;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='获取用户购买商品获得积分次数失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }

    //升级为会员
    public function applyMem($uid)
    {     
        $res = model('user')->where('uid',$uid)->setField('vip',1);
         if ($res) {
            $json['success']='true';
            $json['msg']='升级会员成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='升级会员失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }  
    }
    //升级为采购员
    public function applyCgy($uid)
    {
        $res = model('user')->where('uid',$uid)->setField('userleixing',1);
          if ($res) {
            $json['success']='true';
            $json['msg']='成功成为采购员';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='成为采购员失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }  
    }

    public function delOrder($id){
        $res = model('ordermaster')->where('id',$id)->setField('zhuangtai',-1);
           if ($res) {
            $json['success']='true';
            $json['msg']='订单删除成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='订单删除失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }
   //一般密码柜数据
    public function getYiban()
    { 

        $YibanList = model('ybmimagui')
                      ->alias("y")
                      ->join('user u','u.uid=y.uid','LEFT')
                      ->field('y.bianhao,y.mima,u.uid,u.username')
                      ->where('y.zhuangtai',1)
                      ->select();
              if ($YibanList) {
            $json['success']='true';
            $json['msg']='yibanList';
            $json['data'] = $YibanList;
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='订单删除失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }

     //换柜
     public function editGui($uid)
     {
       $data=[
           'uid'=>$uid,
           'zhuangtai'=>1,
           'mima'=>mt_rand(111111,999999),
       ];
         $count1 = model('ybmimagui')->where('uid',$uid)->setField('zhuangtai',-1);
         $count2 = model('ybmimagui')->insertGetId($data);
          if ($count1&&$count2) {
            $json['success']='true';
            $json['msg']='换柜成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='换柜失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
     }

     //修改柜密码
     public function editPass($bianhao)
     {
        $count = model('ybmimagui')->where('bianhao',$bianhao)->setField('mima',mt_rand(111111,999999));
          if ($count) {
            $json['success']='true';
            $json['msg']='密码修改成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='密码修改失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }
     }


   //鲜活密码柜数据
    public function getXH()
    { 

        $XHList = model('xhmimagui')
                      ->alias("x")
                      ->join('user u','u.uid=x.uid','LEFT')
                      ->field('x.bianhao,x.mima,u.uid,u.username')
                      ->where('x.zhuangtai',1)
                      ->select();
              if ($XHList) {
            $json['success']='true';
            $json['msg']='成功获取鲜活密码柜数据';
            $json['data'] = $XHList;
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='鲜活密码柜数据获取失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
    }


      //换柜
     public function editXhGui($uid)
     {
       $data=[
           'uid'=>$uid,
           'zhuangtai'=>1,
           'mima'=>mt_rand(111111,999999),
       ];
         $count1 = model('xhmimagui')->where('uid',$uid)->setField('zhuangtai',-1);
         $count2 = model('xhmimagui')->insertGetId($data);
          if ($count1&&$count2) {
            $json['success']='true';
            $json['msg']='换柜成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='换柜失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         } 
     }

      //修改柜密码
     public function editXhPass($bianhao)
     {
        $count = model('xhmimagui')->where('bianhao',$bianhao)->setField('mima',mt_rand(111111,999999));
          if ($count) {
            $json['success']='true';
            $json['msg']='密码修改成功';
            $json['status']=200;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }else{
            $json['success']='false';
            $json['msg']='密码修改失败';
            $json['status']=500;
            $m = json_encode($json,JSON_UNESCAPED_UNICODE);
            echo $m;
         }
     }
}
